<template>
	<view class="container">
		<view class="listWrapper">
			<view v-for="item in itemList" class="item" v-on:click="onItem(item)">
				{{item.Name}}
			</view>
		</view>
	</view>
</template>

<script>
	import http from "../../common/http.js"
	import common from "../../common/common.js"
	export default {
		data() {
			return {
				itemList:[]
			}
		},
		onLoad(options) {
			var self = this
			http.get("/store/catetree", {}, (res)=> {
				self.cates = res
				if (options.from == "search") {
					self.cates.splice(0, 0,{'Name':'全部', 'ParentId':0});
				}
				
				self.itemList = self.refreshItemList(0)
			})
		},
		methods: {
			onItem(item) {
				var xxx = this.refreshItemList(item.Id)
				if (xxx.length > 0) {
					this.itemList = xxx
				}else{
					uni.setStorageSync("cate", item)
					uni.navigateBack({
						
					})
				}
			},
			refreshItemList(parentId){
				var self = this
				var itemList = []
				for (var i=0;i<self.cates.length;i++) {
					if (self.cates[i]["ParentId"] == parentId) {
						itemList.push(self.cates[i])
					}
				}
				return itemList
			}
		}
	}
</script>

<style>
	page {
		width: 100%;
		height: 100%;
		background-color: #F3F3F2;
	}
	.item {
		background-color: white;
		line-height: 44px;
		padding: 0px 15px;
		height: 44px;
		margin-bottom: 1px;
		font-size: 18px;
	}
</style>
